package cn.com.djin.ssm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.djin.ssm.entity.Good;
import cn.com.djin.ssm.entity.GoodType;
import cn.com.djin.ssm.entity.Gpicture;

/**
 * 
 * @author ys 商品控制器
 */
@Controller
@RequestMapping("/good")
public class GoodController extends BaseController<Good> {

	// 去前台商品显示页面
	@RequestMapping("/showIndex")
	public String showInidex(Model model) {
		try {
			Good good = new Good();
			GoodType goodtype = new GoodType();
			for (int i = 1; i < 4; i++) {
				goodtype.setTid(i);
				good.setGoodType(goodtype);
				model.addAttribute("goodType" + i, baseService.findManyByPramas(good, 1, 4));
			}
			model.addAttribute("Discounts", goodService.findManyByDiscountSort(1, 8));
			Good testGood = new Good();
			model.addAttribute("showAlls", baseService.findManyByPramas(testGood, 1, 4));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "front/index";
	}

	// 去前台底部显示页面 单条件查询
	@RequestMapping("/goodOneTerm")
	public String goodOneTerm(Model model) {
		try {
			model.addAttribute("goodTypes", goodTypeService.findAll());
			model.addAttribute("colors", goodColorService.findAll());
			model.addAttribute("sizes", goodSizeService.findAll());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "front/showGoods";
	}

	// 去前台底部显示页面 单条件查询
	@RequestMapping("/goodDetails")
	public String goodDetails(Good good, Model model) {
		Gpicture gpicture = new Gpicture();
		gpicture.setGood(good);
		try {
			Good testGood = new Good();
			model.addAttribute("Discounts", baseService.findPageByPramas(1,4,testGood));
			model.addAttribute("goods", goodService.findObjectByPramas(good));
			model.addAttribute("gpictures", gpictureService.findManyByPramas(gpicture));
			model.addAttribute("goodcolors", goodColorService.findGoodColorByGid(good.getGid()));
			model.addAttribute("goodsizes", goodSizeService.findGoodSizeByGid(good.getGid()));
			
		} catch (Exception e) {

			e.printStackTrace();
		}
		return "front/goodDetails";

	}
}
